﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.mediator;
using SharpSqlAnalyzer.pp.mediator.type;
using SharpSqlAnalyzer.pp.utils;

namespace SharpSqlAnalyzer.pp.processor.type.comm
{
	// Token: 0x0200024C RID: 588
	public class AppendNewLineAfterAndBeforeReverseKeyWordProcessor : AbstractProcessor
	{
		// Token: 0x0600131D RID: 4893 RVA: 0x0031CB18 File Offset: 0x0031AD18
		public override void process(TParseTreeNode node)
		{
			bool parameter = this.getParameter<bool>(typeof(bool));
			string parameter2 = this.getParameter<string>(typeof(string), 1);
			string parameter3 = this.getParameter<string>(typeof(string), 2);
			this.getParameter<TSourceToken>(typeof(TSourceToken), 3);
			TSourceToken tsourceToken = null;
			TSourceToken tsourceToken2 = null;
			if (parameter3 != null)
			{
				tsourceToken = SourceTokenSearcher.lastSelectedNotWhitespaceAndReturnToken(node.startToken, parameter3);
				if (tsourceToken != null)
				{
					tsourceToken2 = SourceTokenSearcher.backforwardSearchNotWhitespaceAndReturnToken(tsourceToken, 3, parameter2);
				}
			}
			else
			{
				tsourceToken2 = SourceTokenSearcher.lastSelectedNotWhitespaceAndReturnToken(node.startToken, parameter2);
			}
			if (tsourceToken2 != null)
			{
				int num = 0;
				KeywordAlignMediator mediator = MediatorFactory.getMediator<KeywordAlignMediator>(typeof(KeywordAlignMediator), this.Option.sessionId);
				if (mediator.CurLevelIndentLen > num)
				{
					num = mediator.CurLevelIndentLen;
				}
				mediator.addIndentLevelItem(tsourceToken2, num);
				SourceTokenOperator.removeWhitespaceAndReturnFromEnd(this.Option, tsourceToken2.container, tsourceToken2.posinlist);
				SourceTokenOperator.addBefore(this.Option, tsourceToken2, SourceTokenOperator.createReturnSourceToken());
				SourceTokenOperator.addBefore(this.Option, tsourceToken2, SourceTokenOperator.createWhitespaceSourceToken(num));
				if (parameter3 == null)
				{
					tsourceToken = tsourceToken2;
				}
				SourceTokenOperator.removeWhitespaceAndReturnFromStart(this.Option, tsourceToken.container, tsourceToken.posinlist + 1);
				if (parameter)
				{
					SourceTokenOperator.addAfter(this.Option, tsourceToken, SourceTokenOperator.createReturnSourceToken());
					SourceTokenOperator.addAfter(this.Option, tsourceToken, SourceTokenOperator.createWhitespaceSourceToken(num + this.Option.indentLen));
					return;
				}
				SourceTokenOperator.addAfter(this.Option, tsourceToken, SourceTokenConstant.WHITESPACE);
			}
		}
	}
}
